﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MobileBg
{
    public partial class MobileBg : System.Web.UI.Page
    {
        private static List<Producer> carsInfo;
        private static List<Extras> extras;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                carsInfo = new List<Producer>(){
                    new Producer(){
                        Name="bmw",
                        Models=new List<Model>(){
                            new Model(){ModelName = "X5"},
                            new Model(){ModelName = "M6"}
                        }
                    },                
                    new Producer(){
                    Name="mercedes",
                    Models=new List<Model>(){
                        new Model(){ModelName = "SLK"},
                        new Model(){ModelName = "S550"}
                        }
                    }
                };
                ddlProducers.DataSource = carsInfo;
                var extras = new[]
                    {
                        new{ID=101,Name="Electronic Windows"},
                        new{ID=102,Name="Parktronic"},
                        new{ID=103,Name="GPS"},
                        new{ID=104,Name="4 doors"},
                    };
                this.checklistlExtas.DataSource = extras;

                var engines = new[]
                    {
                        new{ID=22,Name="Dizel"},
                        new{ID=22,Name="Rotor"},
                        new{ID=22,Name="Benzin"}
                    };
                radiogrpEngine.DataSource = engines;

                Page.DataBind();
                BindModels(null, null);
            }
        }

        protected void BindModels(object sender, EventArgs e)
        {
            Producer producer = carsInfo.FirstOrDefault(p => p.Name == ddlProducers.SelectedValue);
            ddlModels.DataSource = producer.Models;
            ddlModels.DataBind();
        }

        protected void DisplaySelection(object sender, EventArgs e)
        {
            literalResult.Text += "<h1>" + ddlProducers.SelectedItem.Text + " " + ddlModels.SelectedItem.Text + "</h1>";
            foreach (ListItem item in checklistlExtas.Items)
            {
                if (item.Selected)
                {
                    literalResult.Text += "<div>" + item.Text + "</div>";
                }
            }
            literalResult.Text += "<br/>"+radiogrpEngine.SelectedItem.Text;
        }
    }
}